package code.google.jcontainer.test.simple;

import code.google.jcontainer.AbstractContainer;
import code.google.jcontainer.ContainerFactory;
import code.google.jcontainer.test.intercept.InterceptableTestBean;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 * @create 2009-12-21 16:13:37
 */
public class SimpleTestCase {

    private static AbstractContainer simpleContainer;

    @BeforeClass
    public static void setup(){
        // get my simple container by name
        simpleContainer = ContainerFactory.scanPackages("code.google.jcontainer.test").getContainer("SimpleContainer");
    }

    @Test
    public void testSayHello() {
        // get the simple component by name
        SimpleTestBean simpleTestBean = (SimpleTestBean)simpleContainer.getComponent("SimpleTestBean");
        // invoke sayHello
        String words = simpleTestBean.sayHello();
        System.out.println("SimpleTestBean said: " + words);
    }

    @Test
    public void testToString() {
        // get the simple component by name
        SimpleTestBean simpleTestBean = (SimpleTestBean)simpleContainer.getComponent("SimpleTestBean");
        // invoke toString
        System.out.println("ToString: " + simpleTestBean.toString());
    }

    @Test
    public void testIntercept(){
        InterceptableTestBean interceptableTestBean = (InterceptableTestBean)simpleContainer.getComponent("InterceptableTestBean");
        System.out.println("echo 'Hello', get " + interceptableTestBean.echo("Hello"));
    }

}
